import 'package:flutter/material.dart';
import 'dart:math' as math;

void main() => runApp(AnimatedApp());

class AnimatedApp extends StatefulWidget {
  @override
  _AnimatedAppState createState() => _AnimatedAppState();
}

class _AnimatedAppState extends State<AnimatedApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: AnimationPage(),
    );
  }
}

class AnimationPage extends StatefulWidget {
  @override
  _AnimationPageState createState() => _AnimationPageState();
}

class _AnimationPageState extends State<AnimationPage>
    with SingleTickerProviderStateMixin {
  AnimationController animController;
  Animation<double> animation;

  @override
  void initState() {
    super.initState();
    animController = AnimationController(
      duration: Duration(seconds: 5),
      vsync: this,
    );

    final curvedAnimation = CurvedAnimation(
      parent: animController,
      curve: Curves.bounceIn,
      reverseCurve: Curves.easeOut,
    );

    animation = Tween<double>(
      begin: 0,
      end: 2 * math.pi,
    ).animate(curvedAnimation)
      ..addListener(() {
        setState(() {});
      })
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          animController.reverse();
        } else if (status == AnimationStatus.dismissed) {
          animController.forward();
        }
      });

    animController.forward();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SizeTransition(
      child: AnimImage(
        animation: animation,
      ), sizeFactor: animation,
    ));
  }

  @override
  void dispose() {
    animController.dispose();
    super.dispose();
  }
}

class RotatingTransation extends StatelessWidget {
  RotatingTransation({this.angle, this.child});
  final Widget child;
  final Animation<double> angle;
  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: angle,
      builder: (BuildContext context, Widget child) {
        return Transform.rotate(
          angle: angle.value,
          child: child,
        );
      },
      child: child,
    );
  }
}

class AnimImage extends AnimatedWidget {
  AnimImage({@required Animation<double> animation})
      : super(listenable: animation);
  @override
  Widget build(BuildContext context) => Container(
        alignment: Alignment.center,
        padding: EdgeInsets.all(30),
        child: Image.asset(
          'asset/image/resocoder.png',
        ),
      );
}
